<template>
  <div :style="{width: '240px', height: '60px'}" id="miniBar" >
  </div>
</template>
<script>
  import { getAction } from '@/api/manage'
  export default {
    name: 'MiniBar',
    // props: {
    //   dataSource: {
    //     type: Array,
    //     default: () => []
    //   },
    //   width: {
    //     type: Number,
    //     default: null
    //   },
    //   height: {
    //     type: Number,
    //     default: 200
    //   }
    // },
    data () {
      return {
        msg: 'Welcome to Your Vue.js App',
      }
    },
    mounted(){
      this.getData();
    },
    methods: {
      drawLine(date,data){
        // 基于准备好的dom，初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('miniBar'))
        // 绘制图表
        myChart.setOption({
          color: ['#3398DB'],
          tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
              type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis : [
            {
              show:false,
              type : 'category',
              data : date,
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis : [
            {
              show:false,
              type : 'value'
            }
          ],
          series : [
            {
              name:'',
              type:'bar',
              barWidth: '60%',
              data:data
            }
          ]
        });
      },
      getData() {
        let this_ = this;
        this.$nextTick(function () {
          getAction("/statistics-api/orderChart/getOrderConversionRate")
            .then(res => {
              if (res.success) {
                //遍历数组，取出数据
                let date=[],data=[]
                for (let key in res.data) {
                  if(key != 'ordersVO'){
                    date.push(key+"")
                    data.push(res.data[key])
                  }
                }

                this_.drawLine(date,data);
              } else {
                this_.$message.warn("无结果");
              }
            })
            .catch(err => {
            });
        })
      },
    },
  }
</script>